SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

-- Crea vista licencia
-- drop view licencia

create view [dbo].[tab_licencia] as
SELECT	idLicencia as tab_lic_id,
		Descripcion as tab_lic_desc,
		CASE SituacionLaboralAsociada
			WHEN 12 THEN 0 -- sin valor
            WHEN 3 THEN 1 -- con goce
            WHEN 4 THEN 2 -- sin goce
            WHEN 8 THEN 3 -- con %
            WHEN 1 THEN 4 -- extraordinaria
            WHEN 10 THEN 5 -- lic injustificada
            WHEN 11 THEN 6 -- lic justificada
            WHEN 5 THEN 7 -- lic normal
            WHEN 12 THEN 8 -- ninguna
            --ELSE 5
        END as tab_lic_goce_haberes,
		substring(avallegal,CHARINDEX('Art.',avallegal)+4,4) as tab_lic_nro_articulo,
		substring(avallegal,1,CHARINDEX(' Art.',avallegal)) as tab_lic_ley,
		CASE Categoria 
			WHEN 1 THEN 'C' 
			WHEN 2 THEN 'L' 
		END as cte_tipo_lic,
		CASE PierdePresentismo 
			WHEN 'N' THEN 0 
			WHEN 'S' THEN 1 
		END as tab_lic_presentismo,
		DuracionMaxima as tab_lic_cantidad_max,
		porcentaje as tab_lic_porcentaje,
		CASE CuentaIncompatibilidad 
			WHEN 'N' THEN 0 
			WHEN 'S' THEN 1 
		END as tab_lic_incompatibilidad
FROM tb_Licencias

GO
